import { Body, Controller, Get, Post, Query } from '@nestjs/common';
import { MenuService } from './menu.service';
import { RequireLogin, UserInfo } from 'src/custom.decorator';
import { SaveMenuDto } from './dto/save-menu.dto';

@Controller('menu')
@RequireLogin()
export class MenuController {
  constructor(private readonly menuService: MenuService) {}

  @Post('save_menu')
  async saveMenu(
    @Body() createMenu: SaveMenuDto,
    @UserInfo('userId') userId: number,
  ) {
    createMenu.createdBy = userId;
    return await this.menuService.save_menu(createMenu);
  }

  @Get('get_menu_list')
  async getMenuList(
    @Query('page') page: number,
    @Query('size') size: number,
    @Query('filter') filter: string,
    @Query('filterFields') filterFields: string = '',
    @Query('dev') dev: boolean = false,
  ) {
    return await this.menuService.get_menu_list(
      page,
      size,
      filter,
      filterFields,
      dev,
    );
  }
  @Get('get_menu')
  async getMenu(@Query('id') id: number) {
    return await this.menuService.get_menu(id);
  }

  @Get('delete_menu')
  async deleteMenu(@Query('id') id: number) {
    return await this.menuService.delete_menu(id);
  }
}
